﻿Imports DevExpress.XtraEditors

Public Class frmDangnhap

    Private Sub frmDangnhap_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Me.txtUsername.Focus()
    End Sub

    Private Sub frmDangnhap_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        InitComboProject_Thang(Me.icbThang)
        InitComboProject_Nam(Me.spiNam)

        Me.icbThang.EditValue = Date.Now.Month
        Me.spiNam.Value = Date.Now.Year
        Me.txtUsername.EditValue = "admin"
        Me.txtPassword.EditValue = ""

    End Sub

    Private Sub btnThoat_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub btnDangnhap_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDangnhap.Click

        'kiem tra account
        Dim myUserF As New UserF

        If myUserF.ExistsAccount(Me.txtUsername.EditValue.Trim, Me.txtPassword.EditValue.Trim) Then
            Project_Thang = Me.icbThang.EditValue
            Project_Nam = Me.spiNam.EditValue

            'khoi tao cac tham so chung
            Dim myDtb As DataTable
            myDtb = myUserF.GetWhereUserName(Me.txtUsername.EditValue.Trim)
            Project_UserName = myDtb.Rows(0).Item("username")
            Project_UserType = myDtb.Rows(0).Item("usertype")

            Me.Close()
            Me.Hide()

            _frmMenu = New frmMenu
            _frmMenu.ShowDialog()

        Else
            XtraMessageBox.Show("Tên người dùng hoặc mật khẩu không đúng", "Quản lý tiền lương", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.txtUsername.Focus()
        End If
    End Sub

    'next focus
    Private Sub txtTennguoidung_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtUsername.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.txtPassword.Focus()
        End If
    End Sub

    Private Sub txtMatkhau_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.icbThang.Focus()
        End If
    End Sub

    Private Sub icbThang_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles icbThang.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.spiNam.Focus()
        End If
    End Sub

    Private Sub spiNam_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles spiNam.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.btnDangnhap.Focus()
        End If
    End Sub

    
End Class